# frozen_string_literal: true

class RuleEntity
  class GeneralRule
    class Dsl < RuleEntity::GeneralRule
      has_one :formula, as: :formulable, dependent: :destroy

      def deep_clone_to_draft
        entity = super
        entity.create_formula! formula.slice(:type, :content)
        entity
      end

      def update_draft(params)
        super
        update_formula(params[:formula]) if params[:formula].present?
      end

      def force_validate
        super

        validate_formula
      end

      def only_fire?(params)
        formula.fire(params)
      end

      private

      def update_formula(params)
        formula.update! params.slice(:content)
      end

      def validate_formula
        raise 'Unsupported.'
      end
    end
  end
end
